package hk.linkcredit.awardservice.award.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import hk.linkcredit.awardservice.award.mapper.AwardDistributionRatioMapper;
import hk.linkcredit.awardservice.award.domain.entity.AwardDistributionRatio;
import hk.linkcredit.awardservice.award.service.IAwardDistributionRatioService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 奖励分销比Service业务层处理
 *
 * @author african-loan
 * @date 2022-06-24
 */
@Service
public class AwardDistributionRatioServiceImpl extends ServiceImpl<AwardDistributionRatioMapper, AwardDistributionRatio> implements IAwardDistributionRatioService {

    /**
     * 查询奖励分销比
     *
     * @param id 奖励分销比ID
     * @return 奖励分销比
     */
    @Override
    public AwardDistributionRatio selectAwardDistributionRatioById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询奖励分销比列表
     *
     * @param awardDistributionRatio 奖励分销比
     * @return 奖励分销比
     */
    @Override
    public List<AwardDistributionRatio> selectAwardDistributionRatioList(AwardDistributionRatio awardDistributionRatio) {
        return this.list(new QueryWrapper<>(awardDistributionRatio).last("order by id desc"));
    }

    /**
     * 新增奖励分销比
     *
     * @param awardDistributionRatio 奖励分销比
     * @return 结果
     */
    @Override
    public int insertAwardDistributionRatio(AwardDistributionRatio awardDistributionRatio) {
        awardDistributionRatio.setCreateTime(new Date());
        return baseMapper.insert(awardDistributionRatio);
    }

    /**
     * 修改奖励分销比
     *
     * @param awardDistributionRatio 奖励分销比
     * @return 结果
     */
    @Override
    public int updateAwardDistributionRatio(AwardDistributionRatio awardDistributionRatio) {
        awardDistributionRatio.setUpdateTime(new Date());
        return baseMapper.updateById(awardDistributionRatio);
    }

    /**
     * 批量删除奖励分销比
     *
     * @param ids 需要删除的奖励分销比ID
     * @return 结果
     */
    @Override
    public int deleteAwardDistributionRatioByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除奖励分销比信息
     *
     * @param id 奖励分销比ID
     * @return 结果
     */
    @Override
    public int deleteAwardDistributionRatioById(Long id) {
        return baseMapper.deleteById(id);
    }

}
